home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Http Server / •OT_Classes / TAddr.cp next >
Encoding:
Text File  |  1996-01-11  |  2.0 KB  |  73 lines  |  [TEXT/CWIE]

  1. //    TAddrInet.cp - Macintosh OpenTransport network "address family independent" class object
  2. // 
  3. // Apple Macintosh Developer Technical Support
  4. // Written by:  Vinne Moscaritolo
  5. //
  6. //  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
  7. //
  8. // You may incorporate this sample code into your applications without
  9. // restriction, though the sample code has been provided "AS IS" and the
  10. // responsibility for its operation is 100% yours.  However, what you are
  11. // not permitted to do is to redistribute the source as "DSC Sample Code"
  12. // after having made changes. If you're going to re-distribute the source,
  13. // we require that you make it clear in the source that the code was
  14. // descended from Apple Sample Code, but that you've made changes.
  15. // 
  16.  
  17. #include "TAddr.h"
  18. #include "TAddrInet.h"
  19.  
  20.  
  21. // ---------------------------------------------------------------------------
  22. //     TAddr::Factory( Type )
  23. // ---------------------------------------------------------------------------
  24. //    create an address of type
  25.  
  26. TAddr* TAddr::Factory(OTAddressType type)
  27. {
  28.     switch(type)
  29.     {
  30.         case AF_INET: 
  31.             return new TAddrInet();
  32.         
  33.         default:
  34.             return nil;
  35.     }
  36.     
  37. };
  38.  
  39.  
  40. // ---------------------------------------------------------------------------
  41. //     TAddr::Factory( TNetbuf )
  42. // ---------------------------------------------------------------------------
  43. //    create an address from Netbuf
  44.  
  45. TAddr* TAddr::Factory(TNetbuf* n)
  46. {
  47.     OTAddress* addr = (OTAddress*) n->buf;
  48.     
  49.     switch(addr->fAddressType)
  50.     {
  51.         case AF_INET: 
  52.             InetAddress* Iaddr = (InetAddress*) n->buf;
  53.             return new TAddrInet(Iaddr->fHost,Iaddr->fPort);
  54.         
  55.         default:
  56.             return nil;
  57.     }
  58.     
  59. };
  60.  
  61.  
  62. // ---------------------------------------------------------------------------
  63. //     TAddr::TaddrToNetbuf( TNetbuf* )
  64. // ---------------------------------------------------------------------------
  65. //    convert an address to Netbuf
  66.  
  67. void  TAddr::ToNetbuf(TNetbuf* n)
  68. {
  69.     n->buf         =  (UInt8*) this->GetAddr();
  70.     n->len         = this->GetSize();
  71.     n->maxlen     = this->GetMaxSize();
  72. }
  73.